import React from "react";

// 父组件
class Counter extends React.Component {
    // 提供共享状态
    state = {
        count:0,
    }
    handleAdd = ()=>{
        this.setState({
            count:this.state.count+1
        })
    }
    render() {
        return (
            <div>
                <Child1 num={this.state.count}></Child1>
                <Child2 handle={this.handleAdd}></Child2>
            </div>
        )
    }
}

const Child1 = (props) => {
    return <h1>计数器：{props.num}</h1>
}
const Child2 = (props) => {
    return <button onClick={()=>props.handle()}>+1</button>
}

export default Counter